/**
 * @file   map_list.cpp
 * @brief  
 * @encode UTF-8
 * @log    date        author      notes
 *         2021.09.22  Jimmy       first version
 */
#include "map_list.h"

/**
 * @brief  Construct a new Map List:: Map List object
 * @author Jimmy 
 * @date   2021.09.22
 */
MapList::MapList()
{
    mList.clear();
    mWidth = mHeight = 0;
}

/**
 * @brief  Destroy the Map List:: Map List object
 * @author Jimmy 
 * @date   2021.09.22
 */
MapList::~MapList()
{

}

/**
 * @brief  initial
 * @param  width            
 * @param  height           
 * @author Jimmy 
 * @date   2021.09.22
 */
void MapList::init(uint16_t width, uint16_t height)
{
    mWidth  = width;
    mHeight = height;
    uint16_t mapSize = mWidth * mHeight;

    mList.clear();
    mList.resize(mapSize, 0);
}

/**
 * @brief  写入值
 * @param  point            
 * @param  val              
 * @param  dxdy             
 * @author Jimmy 
 * @date   2021.09.23
 */
void MapList::push(Point point, uint8_t val, uint8_t dxdy)
{
    uint16_t index = point.y * mWidth + point.x;

    mList[index] = (dxdy << 4) + val;
}

/**
 * @brief  获取值
 * @param  point            
 * @return uint8_t 
 * @author Jimmy 
 * @date   2021.09.23
 */
uint8_t MapList::pop(Point point)
{
    uint16_t index = point.y * mWidth + point.x;
    return mList[index];
}

/**
 * @brief  Get the Index object
 * @param  point            
 * @return uint8_t 
 * @author Jimmy 
 * @date   2021.09.22
 */
uint8_t MapList::getIndex(Point point)
{
    uint16_t index = point.y * mWidth + point.x;

    return (uint8_t)(mList.at(index) & 0x0F);
}

/**
 * @brief  获取dxdy
 * @param  point            
 * @return uint8_t 
 * @author Jimmy 
 * @date   2021.09.23
 */
uint8_t MapList::getDxDy(Point point)
{
    uint16_t index = point.y * mWidth + point.x;
    return (uint8_t)(mList.at(index) >> 4);
}


/* End of file */
